Node.js – Mongoose – Check if a collection exists

Option 2 is probably the cleanest. Assuming you have a Mongoose Connection object named conn that’s been opened using mongoose.createConnection, you can access the native mongo Db object via conn.db. From there you can call collectionNames which should provide what you’re looking for: conn.db.collectionNames(function (err, names) { // names contains an array of objects that … Read more

$or statement in $elemMatch

Sure it is, just clearing up the syntax but you basically had it: { “opened”: { “$elemMatch”: { “closed”: false, “$or”: [ { “openingEvening”: { “$lte”: currentTime }, “closingEvening”: { “$gte”: currentTime } }, { “openingMorning”: { “$lte”: currentTime }, “closingMorning”: { “$gte”: currentTime } } ] } } } And given a sample idea … Read more

how to post arbitrary json object to webapi

You can have your post method that takes in a HttpRequestMessage to by pass the model binding logic and you can read the content of the request directly: public HttpResponseMessage Post(HttpRequestMessage req) { var data = req.Content.ReadAsStringAsync().Result; // using .Result here for simplicity… … } By the way, the reason why the action that takes … Read more

How to perform a bulk update of documents in MongoDB with Java?

Using the example in the manual on the new bulkWrite() API, consider the following test collection which contains the following documents: { “_id” : 1, “char” : “Brisbane”, “class” : “monk”, “lvl” : 4 }, { “_id” : 2, “char” : “Eldon”, “class” : “alchemist”, “lvl” : 3 }, { “_id” : 3, “char” : … Read more

How to do pagination using range queries in MongoDB?

Since the collection I was paging had duplicate values I had to create a compound index on ProductName and id. Create Compound Index db.ProductGuideItem.ensureIndex({ ProductName:1, _id:1}); This solved my problem. Reference: https://groups.google.com/d/msg/mongodb-user/3EZZIRJzW_A/oYH79npKZHkJ Assuming you have these values: {a:1, b:1} {a:2, b:1} {a:2, b:2} {a:2, b:3} {a:3, b:1} So you do this for the range based … Read more

mongoDB query “WHERE _id > threshold”

Compare like with like The _id key in mongo is not (by default) a string – it is a mongo objectId. You need to compare to the same type to get a meaningful result: var ObjectId = require(‘mongodb’).ObjectID; var oid = new ObjectId(); db.things.find(_id: {$gt: oid}); Don’t read mongoexport files Mongo export files look like … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)