Created
February 27, 2016 10:14
-
-
Save royaltm/d6efef898953f499c09b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// bug using findOneAndUpdate with nested updates in nedb client | |
// https://github.com/scottwrobinson/camo/blob/master/lib/clients/nedbclient.js#L155 | |
const EmbeddedDocument = require('camo').EmbeddedDocument; | |
const Document = require('camo').Document; | |
class Contact extends EmbeddedDocument { | |
constructor() { | |
super(); | |
this.email = String; | |
this.phone = String; | |
} | |
} | |
class Person extends Document { | |
constructor() { | |
super(); | |
this.name = String; | |
this.contact = Contact; | |
} | |
} | |
var connect = require('camo').connect; | |
var database; | |
var uri = 'nedb://memory'; | |
connect(uri).then(() => { | |
return Person.create({name: 'John Doe', contact: {email: '[email protected]', phone: 'NA'}}).save() | |
}).then(person => { | |
return Person.findOneAndUpdate({_id: person._id}, {'contact.phone': '0123456789'}) | |
}).then(person => { | |
// person.contact.phone === 'NA' but it should be '0123456789' !!! | |
console.log('%j', person); | |
return Person.findOne({_id: person._id}) | |
}).then(person => { | |
// person.contact.phone === '0123456789'; | |
console.log('%j', person); | |
}).catch(err => { | |
console.log('oops:', err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment