MONGO DB Alias name usage in find query not working - mongodb

i am using the below command to find records in contacts collection's
db.contacts.find({"field1":"1"})
the problem is i want to use alias name for field1 as SL.NO
i tried this way and its not working...
db.contacts.find({"field :n, as: :SL.NO" : "1"}
can anyne help me in this issue?
BTW I am currently using mongo 1.6.5

Some drivers like Mongoose support that feature, but there is no such feature in MongoDB itself or the Mongo shell.

Related

Executing commands from MongoDB Compass

Is it possible to execute a command such as db.eval("return new Date()") from MongoDB Compass?
Right now I see only collection query commands like filter, project, sort, etc.
Mongo compass provides only filter option (Query Bar) to do queries on specific collection :(
You can read how it works - https://docs.mongodb.com/compass/master/schema/#query-bar
Replying to old thread: Just want to mention that Mongo Compass v1.22 and newer has Embedded Shell which can do shell commands https://docs.mongodb.com/compass/current/embedded-shell/

How can I query an FS collection in Meteor from the command line?

It is very useful to run meteor mongo and query collections from the command line, for debugging purposes, etc.
Recently, I have added the collectionFS package to enable image storage in the database. However, I am unable to query the database from the command line.
db.fs.collection_name.find() is not doing the trick, and I can't seem to find the correct command anywhere.
Go to the Meteor Mongo console: meteor mongo
See all the collections that are available: show collections
Look for the one that has cfs.collection_name.files
Choose the one that has your collection name. For example, I'm using collectionFS with gridFS for images. When I type show collections, I see cfs_gridfs.images.files so I just do: db.cfs_gridfs.images.files.find() to see those files.
Hope that helps.
If you find it difficult to use the command line or terminal, you have a UI for MongoDB called Robomongo which is easy to install and use. I use Meteor with its default port number and then in Robomongo it is used as 3001.
And the query to view collection here is same as db.collection_name.find().

Having problems with MongoDB collection named 'auth'

I have a MongoDB collection named 'auth', and when I run:
db.auth.drop()
It of course conflicts with the db.auth() function that MongoDB provides.
Is there any other way to drop a collection?.
This issue arises when you try to access auth collection from mongo shell as it conflict with db.auth() you mentioned in the question. But using any driver you can perform CRUD on auth collection. I tried using its java driver, it works fine. That's why you faced no issue while using ORM as it is using any mongo driver internally.

MongoDB "j must be numeric or a boolean value"

I've set up my own local mongodb (v. 3.0.2) instance on a local ubuntu version (14.10) and I'm using genghis(v. 2.3.11) to visualize it. My programm is able to create new documents in the database, but when I try to save a newly created document or delete a document in genghis it always returns "j must be numeric or a boolean value" but it still creates/deletes the document. The error doesn't show up when I edit a document. The only thing I could find when I tried to find a solution on google was this: https://github.com/mongodb/mongo/blob/master/src/mongo/db/write_concern_options.cpp which makes me think that it's a problem with my mongodb setup (and has nothing to do with genghis), but I do not know how to resolve this.
Have you tried running the code against Mongo 2?
I ran into this same error when I tried connecting to Mongo 3 from a service that was using client libraries intended for Mongo 2.

How to clear/drop/empty a MongoDb collection with Casbah

I started using MongoDb in Scala via Casbah but cannot find on the Casbah documentation / google the way to drop the content of a collection.
The MongoDd doc says the MongoDb shell command to do so is
db.things.remove({});
But how can we achieve the same via Casbah?
Thanks in advance,
Olivier
Casbah's equivalent to the shells {} empty document operator is `MongoDBObject.empty
This should work -
db.things.remove(MongoDBObject.empty)