These are chat archives for Automattic/mongoose

6th
Jul 2015
Konstantin Melnikov
@archangel-irk
Jul 06 2015 04:42
if ObjectModel is document
ObjectModel.arr.push({"name": "Bob", "age":20});
ObjectModel.save(callback);
In your case, you most likely need to use the option "overwrite"
bluepuma77
@bluepuma77
Jul 06 2015 09:43
Is is possible to sort result by existence? I didn't find any example searching the net.
I would like to get results with any idOrder first, but not sort by idOrder, only by true/false. Something along the lines of this:
Book.find({
    $query: {parent:id}, 
    $orderby: { 
        idOrder: {'$exists':true}, 
        created: -1
    } 
});
sivaram si
@sivaramsi
Jul 06 2015 10:04
Is it possible to update a subdocument inside another subdocument with mongoose
?

var roadMapNodeSchema = new db.Schema({
name:{
type:'String'
},
id:{
type:'String'
},
status:{
type:'String'
}
});
var roadMapListSchema = new db.Schema({
name: {
type: 'String'
},
id: {
type: 'String'
},
nodes:[roadMapNodeSchema],
});

var schema = new db.Schema({
version: {
type: 'String',
required: true
},
roadmap: [teamworkListSchema]
});

here is my schema
bluepuma77
@bluepuma77
Jul 06 2015 10:46
Solved my issue with $orderby: { "idOrder.length": 1, created: -1} }
sivaram si
@sivaramsi
Jul 06 2015 10:59
Too many positional (i.e. '$') elements found in path 'roadmap.$.nodes.$.status' when i try to update the inner sub doc
db.getCollection('roadmaps').update({"roadmap.nodes.id":443898},{$set:{"roadmap.$.nodes.$.status":"completed"}},true,true)
its my query
dragonman123
@dragonman123
Jul 06 2015 15:11
Anyone online for giving some help.?
Erinç Fırtına
@EricMcRay
Jul 06 2015 16:54
here
dragonman123
@dragonman123
Jul 06 2015 17:42
How can I declare schema for the array (name is "information") which contains:-
  1. Images array-> which further contains array of objects..
  2. Videos array -> which further contains array of objects.
  3. texts array-> which further contains array of objects..
  4. id string
This is what I am getting when I am doing console.log of the above thing.
<code>
[ { videos: [ [Object], [Object] ],
images: [ [Object], [Object] ],
texts: [ [Object] ],
id: '7cd46593-b908-47b3-8f3d-f5d153abcc0b' },
{ videos: [ [Object], [Object] ],
images: [ [Object], [Object] ],
texts: [ [Object], [Object] ],
id: 'f2573b8d-6796-456f-8b1b-0485f3707f36' } ]
</code>
dragonman123
@dragonman123
Jul 06 2015 18:03
Leave it, I got the answer.. :P