var schema = new mongoose.Schema({
name : {
first : String,
last : String,
},
points : [ { x: Number, y: Number } ],
});
var Shape = mongoose.model( 'Shape', schema );
var s = new Shape({
name : {
first : 'frank',
last : 'smith',
},
points : [
{ x : 1, y : 1 },
{ x : 2, y : 2 },
],
});
console.log( JSON.stringify( s, undefined, 2 ) );
/*
as expected:
{
"_id": "538f7cfb5fa6f8702350a78a",
"points": [
{
"x": 1,
"y": 1,
"_id": "538f7cfb5fa6f8702350a78c"
},
{
"x": 2,
"y": 2,
"_id": "538f7cfb5fa6f8702350a78b"
}
],
"name": {
"first": "frank",
"last": "smith"
}
}
*/
s.set( 'points.1.y', 10 );
s.set( 'name.first', 'James' );
console.log( JSON.stringify( s, undefined, 2 ) );
/*
s.set completely clobbered s.points[1]. x and _id props are gone!
{
"_id": "538f7cfb5fa6f8702350a78a",
"points": [
{
"x": 1,
"y": 1,
"_id": "538f7cfb5fa6f8702350a78c"
},
{
"y": 10
}
],
"name": {
"first": "James",
"last": "smith"
}
}
*/
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for your reply.My use case involves storing a path within a document as a string and accessing the value through that path. I created the example to demonstrate in the simplest way why document#set does not work as I was expecting.