Domanda

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
È stato utile?

Soluzione

You should try:

db.testData.insert(j)

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

>mapData = db
>mapData.testData.insert(j)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top