Reputation: 791
I'm trying to generate a UUID when a form is filled out and is posted to the server. MongoDB is picking up all the records except for userId. Ideally I want the UUID to be the parent, unique to each user (which I'll store in a cookie), and entry search
submission will be the child of the UUID.
How come the UUID is not being stored along with the search data if it's being produced and available. I've changed the userId
in the schema from Number
to String
with no avail.
Mongoose Schema
var SearchSchema = mongoose.Schema({
userId: String,
search: {
firstName: String,
lastName: String,
email: String
}
})
Save data to DB
var firstName = req.body.firstName
var lastName = req.body.lastName
var email = req.body.email
var userID = generateUUID()
console.log(userID) // This works
// Push to DB
var data = new Search({
userID: userID, // This doesn't appear to be stored
search: {
firstName: firstName,
lastName: lastName,
email: email
}
})
Search.createSearch(data, function(err, search){
if (err) throw err
console.log('hello' + search)
})
Console
{ search:
{ email: '@rhysedwards.com',
lastName: 'edwards',
firstName: 'rhys' },
_id: 5720d8211a44fac4dd6657c1 }
Upvotes: 0
Views: 229
Reputation: 69663
Fields in MongoDB/Mongoose are case sensitive. Your schema calls the field userId
but the object you store in the database has the field userID
. Note the capitalization of the D
.
Upvotes: 3