Tag: mongodb-query

54 votes
22 answers
937 views
Get names of all keys in the collection

I'd like to get the names of all the keys in a MongoDB collection. For example, from this: db.things.in

avatar
Joseph
0 1 0 9
asked 07 September, 2021
54 votes
28 answers
1K views
Random record from MongoDB

I am looking to get a random record from a huge collection (100 million records). What is the fastest and most

avatar
Karolyn
0 1 0 9
asked 07 September, 2021
51 votes
15 answers
1.5K views
How to remove a field completely from a MongoDB document?

{ name: 'book', tags: { words: ['abc','123'], lat: 33,

avatar
Keila
0 1 0 9
asked 07 September, 2021
59 votes
14 answers
2.5K views
Retrieve only the queried element in an object array in MongoDB collection

Suppose you have the following documents in my collection: { "_id":ObjectId("562e7c594c12942f08fe4192"),

avatar
Clarice
0 1 0 9
asked 07 September, 2021
59 votes
11 answers
2K views
Update MongoDB field using value of another field

In MongoDB, is it possible to update the value of a field using the value from another field? The equivalent

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
53 votes
15 answers
1.6K views
Find objects between two dates MongoDB

I've been playing around storing tweets inside mongodb, each object looks like this: { "_id" : ObjectId(

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
48 votes
14 answers
3.1K views
Query for documents where array size is greater than 1

I have a MongoDB collection with documents in the following format: { "_id" : ObjectId("4e8ae86d08101908e10

avatar
Benton
0 1 0 9
asked 07 September, 2021
49 votes
30 answers
1.3K views
How to query MongoDB with "like"

I want to query something with SQL's like query: SELECT * FROM users WHERE name LIKE '%m%' Ho

avatar
Shanita
0 1 0 9
asked 07 September, 2021