Question

I am trying to insert to a collection in my empty database,I get a reference error that says the database was not created:

mapdata (empty)
> db
mapdata
> j={name:"mongo"};
{ "name" : "mongo" }
> k={x:3};
{ "x" : 3 }
> mapdata.testData.insert(j);
Tue Mar 11 23:03:10.704 ReferenceError: mapdata is not defined
> db
mapdata
> mapdata.testData.insert(j);
Tue Mar 11 23:03:32.163 ReferenceError: mapdata is not defined
> use mapdata;
switched to db mapdata
> mapdata.testData.insert(j);
Tue Mar 11 23:04:02.288 ReferenceError: mapdata is not defined
Was it helpful?

Solution

You should try:

db.testData.insert(j)

Or if you want to use "mapData" as the db name:

>mapData = db
>mapData.testData.insert(j)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top