In Mongo, how do I display the indexes of a collection? [duplicate] - mongodb

This question already has answers here:
A list of indices in MongoDB?
(7 answers)
Closed 8 years ago.
I just want to display all the indexes in the shell.

If you want raw access to the indexes, you can query the db.system.indexes collection:
> db.system.indexes.find()
To find the indexes for a specific collection, you can do:
> db.collection.getIndexes()
See this question.

Related

Golang MongoDB Driver return ordered field [duplicate]

This question already has answers here:
Using MongoDB Projection
(1 answer)
How to filter fields from a mongo document with the official mongo-go-driver
(1 answer)
Closed 8 months ago.
There are lots example about how to use go mongodb driver, but less or no example about return ordered field. For example, my document has lots of feilds, but I only want my mongo query return some of fields. Can anyone help me?
https://github.com/mongodb/mongo-go-driver

Is there anyway to use mongodb to search for ANY instead of omit the query? [duplicate]

This question already has answers here:
Programmatically build dynamic query with Mongoose
(3 answers)
Dynamic queries in MongoDB and Node.js
(2 answers)
Closed 5 years ago.
Is there anyway to use mongodb to search for ANY instead of omit the query.
Example
db.users.find({country:"Vietnam", gender:ANY}).pretty()
instead of
db.users.find({country:"Vietnam"}).pretty()

MongoDB only removing first field from the collection [duplicate]

This question already has answers here:
Why this update query only update one record once
(3 answers)
Closed 7 years ago.
I'm a beginner in MongoDb.I wanted to know what is the query to remove a field in Mongo DB Collection.I have tried with
db.Component.update({},{$unset: {vendor:""}}).
Its was updating only first document.So How to remove field Completely from Collection?
Try this-db.Component.update({},{$unset: {vendor:""}},false,true)
Here false

Mongodb - Finding a field value existence in another field [duplicate]

This question already has answers here:
MongoDb query condition on comparing 2 fields
(4 answers)
Closed 8 years ago.
Is it possible to find all documents in a collection where documents with field (_id) values exist in another field (ex. parentID). Taking in consideration that both fields exist in the documents of the same collection? Thanks
Categories.find({'_id': 'parentID'})
{
_id: 11,
parentID: 1
}
I am using MongoDB 2.6.7
Yes, this is easy to do with the $where operator.
db.Categories.find({'$where':"this._id === this.parent"})
This gives you more flexibility than your regular find syntax but be warned that MongoDB needs to evaluate the Javascript so this is slower than a regular query.

mongodb $in limit [duplicate]

This question already has answers here:
What is the maximum number of parameters passed to $in query in MongoDB?
(4 answers)
Closed 6 years ago.
Was just wondering if there is a limit to Mongodb's $in function?
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24in
I have a collection of users (BIG) and have a smaller subset of ObjectIds stashed somewhere, and I want to select all users (collections) that are in my ObjectIds.
Thanks
Since there's no limit on the number of items in an array as such, you shouldn't have any problem..
For the case when the array is embedded inside a document, you might want to have a look at these:
http://groups.google.com/group/mongodb-user/browse_thread/thread/4a7caeba972aa998?fwc=1
Filtering content based on words
http://groups.google.com/group/mongodb-user/browse_thread/thread/28ae76e5ad5fcfb5