How to insert the data into mongoDB collection manually - mongodb

I want to insert the data into Robo3T manually. I tried using insert and insertMany command, but nothing works for me. Please provide me the solution if it's possible.

db.getCollection('YourCollectionName').insert({"name" : "ABC"})

Related

Bulk insert in Mongodb and Postgresql

I am doing a comparison on Postgresql vs Mongodb on insert.I am using the copy command (from file to table) in Postgresql and i am wondering what is the equivalent command in mongodb.I think that the answer is the insert_many(dict)But i want be sure.Any advice would be appreciated.Thanks in advance!
If you want to insert multiple documents in mongodb, you can use
db.collectionName.insertMany([{title: 'doc 1'},{title: 'doc2'},......]}

MongoDb db.collection.find() With Special Character

I am trying to write a simple query in MongoDb using PyMongo driver as such
mongo.db.people.find_one({'name': 'Tést Name'})
mongo.db.people.find_one({'name': 'Test_O%27Name'})
Both of these queries are returning null. I have checked to make sure the data exists in the db. How do I change the query so that find() is able to find it?
Thanks
You can use like this
db.myCollection.find({ myKey : /.*\$tes.*/i });
You have to escape $ by :

Delete data from a collection in mongo db by using multiple conditions

I am new to mongo db
using i have to delete data from a table like
select from table where id=12 and browser =GC
But I dont know how to perform this in mongo db?
Use remove
db.collectionName.remove({'_id':12,'browser':"GC"})
Can provide more accurate answer if you show your collection and documents .

Is there a better way to export a mongodb query to a new collection?

What I want:
I have a master collection of products, I then want to filter them and put them in a separate collection.
db.masterproducts.find({category:"scuba gear"}).copyTo(db.newcollection)
Of course, I realise the 'copyTo' does not exist.
I thought I could do it with MapReduce as results are created in a new collection using the new 'out' parameter in v1.8; however this new collection is not a subset of my original collection. Or can it be if I use MapReduce correctly?
To get around it I am currently doing this:
Step 1:
/usr/local/mongodb/bin/mongodump --db database --collection masterproducts -q '{category:"scuba gear"}'
Step 2:
/usr/local/mongodb/bin/mongorestore -d database -c newcollection --drop packages.bson
My 2 step method just seems rather inefficient!
Any help greatly appreciated.
Thanks
Bob
You can iterate through your query result and save each item like this:
db.oldCollection.find(query).forEach(function(x){db.newCollection.save(x);})
You can create small server side javascript (like this one, just add filtering you want) and execute it using eval
You can use dump/restore in the way you described above
Copy collection command shoud be in mongodb soon (will be done in votes order)! See jira feature.
You should be able to create a subset with mapreduce (using 'out'). The problem is mapreduce has a special output format so your documents are going to be transformed (there is a JIRA ticket to add support for another format, but I can not find it at the moment). It is also going to be very inefficent :/
Copying a cursor to a collection makes a lot of sense, I suggest creating a ticket for this.
there is also toArray() method which can be used:
//create new collection
db.creatCollection("resultCollection")
// now query for type="foo" and insert the results into new collection
db.resultCollection.insert( (db.orginialCollection.find({type:'foo'}).toArray())

MongoDB - mongohub gui - queries by _id objectid type

I am using MongoHub GUI for MongoDB: http://mongohub.todayclose.com/
I would like to be able to query by ObjectId as this is what MongoHub is returing for _id. How to do this, something like {"_id":"4d1b4687a6d5437619000000"} is not working??
cheers,
/Marcin
try following code:
{"_id": ObjectId("4d1b4687a6d5437619000000")}
check this for more details
It looks as if MongoHub is broken in the case of supplying a function in a query (ObjectId, as galimy rightly suggested). If you enter the query as galimy suggested, then copy and paste the full query that MongoHub says it's going to execute (grayed out above the Query text input) into a connected mongo CLI console, it works fine.
I would recommend learning to use the mongo console -- I've found two bugs in 5 minutes of playing with MongoHub, and when you're typing in JSON for your queries anyway the GUI is doing very little for you.
OK, it has been fixed in recent MongoHub release. Cheers
{"_id": { $oid: "4d1b4687a6d5437619000000"}} definitely should work. Java MongoDB driver implicitly creates ObjectId object in the object has '$oid' property.
Also all the same is for date using '$date' property.