How to filter fields from a mongo document with the official mongo-go-driver

Edit: As the mongo-go driver evolved, it is possible to specify a projection using a simple bson.M like this: options.FindOne().SetProjection(bson.M{“_id”: 0}) Original (old) answer follows. The reason why it doesn’t work for you is because the field fields._id is unexported, and as such, no other package can access it (only the declaring package). You must … Read more

How to increment a field in mongodb?

As the error indicates, on the client you can only perform an update with a simple _id selector. I’d recommend using a method with a slight modification to your code: Meteor.methods({ incClicks: function(id, news) { check(id, String); check(news, Match.ObjectIncluding({link: String})); News.update( {_id: id, ‘items.link’: news.link}, {$inc: {‘items.$.clicks’: 1}} ); } }); Here we are using … Read more

Mongo unique index case insensitive

Prior of MongoDB version 3.4 we were unable to create index with case insensitive. In version 3.4 has collation option that allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. The collation option has the following syntax: collation: { locale: <string>, caseLevel: <boolean>, caseFirst: <string>, strength: <int>, … Read more

mongodb : Increasing max connections in mongodb

You also need bump up the number of file descriptors and number of file descriptors per process that the Linux kernel allows. In Linux, this should be configured by editing the file at /proc/sys/fs/file-max or by the sysctl utility. Edit the /etc/sysctl.conf file and add fs.file-max = 50000. This sets the maximum file descriptors that … Read more

Mongodb, aggregate query with $lookup

For any particular person document, you can use the populate() function like var query = mongoose.model(“person”).find({ “name”: “foo” }).populate(“projects.tags”); And if you want to search for any persons that have any tag with ‘MongoDB’ or ‘Node JS’ for example, you can include the query option in the populate() function overload as: var query = mongoose.model(“person”).find({ … Read more

MongoDB count() versus countDocuments()

The db.collection.find method returns a cursor. The cursor.count() method on the cursor counts the number of documents referenced by a cursor. This is same as the db.collection.count(). Both these methods (the cursor.count() and db.collection.count()) are deprecated as of MongoDB v4.0. From the documentation: MongoDB drivers compatible with the 4.0 features deprecate their respective cursor and … Read more