Find document with array that contains a specific value

As favouriteFoods is a simple array of strings, you can just query that field directly: PersonModel.find({ favouriteFoods: “sushi” }, …); // favouriteFoods contains “sushi” But I’d also recommend making the string array explicit in your schema: person = { name : String, favouriteFoods : [String] } The relevant documentation can be found here: https://docs.mongodb.com/manual/tutorial/query-arrays/

How to get the last N records in mongodb?

If I understand your question, you need to sort in ascending order. Assuming you have some id or date field called “x” you would do … .sort() db.foo.find().sort({x:1}); The 1 will sort ascending (oldest to newest) and -1 will sort descending (newest to oldest.) If you use the auto created _id field it has a … Read more

When to use CouchDB over MongoDB and vice versa

Of C, A & P (Consistency, Availability & Partition tolerance) which 2 are more important to you? Quick reference, the Visual Guide To NoSQL Systems MongodB : Consistency and Partition Tolerance CouchDB : Availability and Partition Tolerance A blog post, Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase vs Membase vs Neo4j … Read more

MongoDB vs. Cassandra [closed]

Lots of reads in every query, fewer regular writes Both databases perform well on reads where the hot data set fits in memory. Both also emphasize join-less data models (and encourage denormalization instead), and both provide indexes on documents or rows, although MongoDB’s indexes are currently more flexible. Cassandra’s storage engine provides constant-time writes no … Read more

How can I list all collections in the MongoDB shell?

You can do… JavaScript (shell): db.getCollectionNames() Node.js: db.listCollections() Non-JavaScript (shell only): show collections The reason I call that non-JavaScript is because: $ mongo prodmongo/app –eval “show collections” MongoDB shell version: 3.2.10 connecting to: prodmongo/app 2016-10-26T19:34:34.886-0400 E QUERY [thread1] SyntaxError: missing ; before statement @(shell eval):1:5 $ mongo prodmongo/app –eval “db.getCollectionNames()” MongoDB shell version: 3.2.10 connecting … Read more

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