How to use $mod operator from mongodb in Golang - mongodb

I checked the usage of $mod operator in mongo, but I could not find how to query the same using Golang.
Usage in mongo:
{fieldName:{$mod:[24,0]}}
Expecting the usage in Golang

You can directly translate that to a bson.M object:
bson.M{"fieldName":bson.M{"$mod":[]int{24,0}}}

Related

How do I replicate this mongodb regex in query using mongo-scala-driver?

I can query mongodb directly using this query {key: {$in: [/faq/]}} but how do I replicate this when using Filters#in?
in("key", Seq("/faq/")) doesn't work as it gets passed as a string.

MongoDb db.collection.find() With Special Character

I am trying to write a simple query in MongoDb using PyMongo driver as such
mongo.db.people.find_one({'name': 'Tést Name'})
mongo.db.people.find_one({'name': 'Test_O%27Name'})
Both of these queries are returning null. I have checked to make sure the data exists in the db. How do I change the query so that find() is able to find it?
Thanks
You can use like this
db.myCollection.find({ myKey : /.*\$tes.*/i });
You have to escape $ by :

Alternative for mongodb $push function in postgres

Converting the MongoDb queries into postgresql.
In mongoDb we the basic usage of $push is as follows :
https://docs.mongodb.org/v3.0/reference/operator/aggregation/push/
Is there any alternative for this in postgresql or we need to implement it using the code.
You can do this using array_agg function in Postgres.
See Sample code(shamelessly copied ) : http://www.sqlfiddle.com/#!15/21b2b/1

Updating in mongodb

There is a collection in mongoDB:
info = {
"name":"me",
"note":[
{"date":"Dec.01",
"item":"01",
},
{"date":"Dec.02",
"item":"02",
}
]
}
Using pymongo, how do I push {"date":"Dec.03","item":"03"} to the key "note" directly?
Just perform a regular update operation using pymongo, and use the $push operator provided by MongoDB itself. So something like this:
collection.update({"name":"me"},{$push:{"note":{"date":"Dec.03","item":"03"}}});
Here's some documentation on the $push operator: http://docs.mongodb.org/manual/reference/operator/update/push/
Also, note how the $push operator is actually part of MongoDB itself, so most packages that use Mongo, like pymongo in your case, will support this operator.
You may use the $addToSet operator (see documentation).

MongoDB $or query in Meteor?

The mongodb $or operator works as intended outside of a meteorjs context:
db.users.find({$or: [{email: 'some#mail.com'},{city: 'atlanta'}]});
I get results for any document that has email some#mail.com or city of atlanta.
The same query in Meteor syntax doesn't yield the same results :
Users = new Meteor.Collection("users");
Users.find({$or: [{email: 'some#mail.com'},{city: 'atlanta'}]});
I've read the meteor docs - http://docs.meteor.com/#find - and since it doesn't say anything about it, I'm assuming it should run just the same as a mongodb 1.6+ instance?
find returns a cursor object. You need to use a fetch to get the array of values. Try:
console.log(Users.find({$or: [{email: 'some#mail.com'},{city: 'atlanta'}]}).fetch());