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

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)

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/

Java MongoDB driver can't parse query

I'm developing project with hibernate-ogm 5 with mongodb 3. But some query can not parsed. But I tested this query on shell. It works. What's wrong with this query?
com.mongodb.util.JSONParseException:
db.Tree.update({'_id':2},{'$inc':{'totalUserCount':NumberInt(-1)}},{})
^
com.mongodb.util.JSONParser.parse(JSON.java:230)
com.mongodb.util.JSONParser.parse(JSON.java:155)
com.mongodb.util.JSON.parse(JSON.java:92)
com.mongodb.util.JSON.parse(JSON.java:73)
org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.MongoDBQueryDescriptorBuilder.build(MongoDBQueryDescriptorBuilder.java:71)
FYI, the parsing issue will be fixed in the next release of OGM.
Note that it will support NumberLong but not NumberInt as NumberInt is not supported by the MongoDB Java Driver: https://jira.mongodb.org/browse/JAVA-2185 .
The use of functions like NumberInt is not supported at the moment.
I've created an issue for it: https://hibernate.atlassian.net/browse/OGM-1027

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.

MONGO DB Alias name usage in find query not working

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.

Access MongoDB in Hadoop?

I combine the MongoDB into Hadoop by using MongoDB-Hadoop plugins.
( http://www.mongodb.org/display/DOCS/Hadoop+Quick+Start )
I found that PHP could access HBase by using Thrift.
Is it possible to access ( read / write ) MongoDB by using PHP and Thrift, or any other solutions ?
Thanks
If you want to query MongoDB with PHP and an ODM, you should take a look on
Doctrine or Lithiums Data Mapper
Doctrine: Doctrine Info
Lithium: Lithium PHP Library
I am sure, that you could easily use lithium mappers to start hadoop jobs and querying hadoop.