These are chat archives for Automattic/mongoose

25th
Mar 2016
antonioaltamura
@antonioaltamura
Mar 25 2016 02:13
@wfhio _id is just an unique id, it could be a String or a Number too.
@saurabhvyas have you tried
results = memory.find( { 'metadata.itemcount': 0 }});
guys maybe someone could help here?
http://stackoverflow.com/questions/36105189/query-on-hierarchical-ref
Basically I have to model the 'law' collection in chapters and paragraphs. The 'document' collection could have a ref to a chapter or a paragraph. I simply need a method to get all the documents that refs to the X chapter (and its paragraphs too!)
Wojtczyk
@awojtczyk
Mar 25 2016 07:41

Hi there, i have question about population.
My model looks like that:

var ListItemSchema = new mongoose.Schema({
    date:{ type: Date, default: Date.now },
    postedBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    },
    product: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Product'
    },
    qty: { type: Number, max: 100 }
});

So why aint getting postedBy model populated, while running this query:

ListItem
            .find({'$where': 'this.date.toJSON().slice(0, 10) == "'+d+'"'})
            .populate('product')
            .populate('postedBy')
            .exec(function (error, products) {
                    if (error) {
                    return handleError(error);
                }
                else {
                    return res.status(200).json({products: products})
                }
            })
Wojtczyk
@awojtczyk
Mar 25 2016 12:35
To answer myself if someone would need:
var populateQuery = [
            {path: 'product', select: 'name price'},
            {path: 'postedBy', select: 'email first_name last_name'}
        ];

        ListItem.find({'$where': 'this.date.toJSON().slice(0, 10) == "' + d + '"'})
            .populate(populateQuery)
...
Erinç Fırtına
@EricMcRay
Mar 25 2016 13:30
how can i validate embeded document field value by field which from parent document?
I tried this.parent(), this.parentArray() but did not work.
Richard Brookfield
@dvideby0
Mar 25 2016 13:38
Quick question. I am working with mongos shards and looking to have auto-failover. Is this a valid configuration (seems to work)
var config = {
mongos: {
        ssl: true,
        sslCA: certFile
      }
}
mongoose.connect(uri, config);
Erinç Fırtına
@EricMcRay
Mar 25 2016 14:05
@dvideby0 if your uri is correct it will work :)
Richard Brookfield
@dvideby0
Mar 25 2016 14:06
awesome thank you.. the uri is comma separated URIs similar to how you would specify replica sets.. Is that still ok too? @EricMcRay
and thanks for the quick response too
dreamiverse
@dreamiverse
Mar 25 2016 16:19
golang
/join #golang
hmm