These are chat archives for Automattic/mongoose

29th
Feb 2016
Raimo Pitkänen
@rapitkan
Feb 29 2016 11:59
Is it possible to generate _id field for object in arrays afterwards?
I had _id: false but now I need the id’s. How should I update existing documents?
antonioaltamura
@antonioaltamura
Feb 29 2016 13:44
guys can I see a wildcard text usage example (https://docs.mongodb.org/manual/core/index-text/#wildcard-text-indexes) I'm founding difficult to use it. I need to do full-text search (on all text fields)..what's the proper way?
J
@jhyland87
Feb 29 2016 15:04
Hey guys. If im trying to find documents, but ignore an array of document ObjectIds, would this be the way to go?
{ _id: {$ne: { $in: [ ObjectId("56d0808066b93cad49dbbbe5"), ObjectId("56d0819f655baf4a4a7f9cc9") ] } } }
Or is there a not-$in kinda operator
J
@jhyland87
Feb 29 2016 15:26

When I try this:

this.find({
    _id: {
        $ne: {
            $in: [ '56d462514d7ea56164bcf9f6', '56d0808066b93cad49dbbbe7' ]
        } 
    }
})

I receive an error:

{ [CastError: Cast to ObjectId failed for value "[object Object]" at path "_id"]
  message: 'Cast to ObjectId failed for value "[object Object]" at path "_id"',
  name: 'CastError',
  kind: 'ObjectId',
  value: { '$in': [ '56d462514d7ea56164bcf9f6', '56d0808066b93cad49dbbbe7' ] },
  path: '_id',
  reason: undefined }
J
@jhyland87
Feb 29 2016 15:33

This is odd, the array is getting casted to an object.. I added this just before the find() execution in my JS:

            if( data.ignore ){
                console.log('# --------------------')
                console.log('# WHERE:',where)
                console.log('# IGNORE:',where._id['$ne']['$in'] )
            }
            this.find( where )

And the console output:

# WHERE: { _partition: '56d4643934742e9364c52a2c',
  _id: { '$ne': { '$in': [Object] } } }
# IGNORE: [ '56d4643934742e9364c52a32', '56d0808066b93cad49dbbbe7' ]
I was thinking maybe its an issue with the query, but I tested it via MongoDB: db.assets.find( { _id: {$ne: { $in: [ ObjectId("56d0819f655baf4a4a7f9cc9") ] } } } ).pretty()
Rafiullah Hamedy
@rhamedy
Feb 29 2016 19:54
Hi guys, having issue running an update query using Mongoose, it executes without any error and returns zero
This message was deleted
imageRecord.update({"vid": doc.vid}, {$addToSet: {"images": {$each: doc.images}}}, function(err, response) {
            if(err) {
              console.log("(exist) Failed to save docoument images. " + JSON.stringify(err));
            } else {
              console.log("Response >> " + response);
            }
            callback(null);
          });
Rafiullah Hamedy
@rhamedy
Feb 29 2016 20:00
running the same update query using mongodb shell works just fine
Rafiullah Hamedy
@rhamedy
Feb 29 2016 22:02

I had to retrieve the record first and then do something as follow

doc.images.forEach(function(img) {
       record.images.addToSet(img);
 });

Followed by

record.save(function(err, response) {
});