4
I’m new in Mongo, I’m trying to make an Insert in the bank but it’s a problem when inserting
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
public class InsertDriver {
public static void main(String[] args) throws UnknownHostException {
DB dB = (new MongoClient("localhost", 27017)).getDB("realdatabase");
DBCollection dBCollection = dB.getCollection("Channel");
BasicDBObject basicDBObject = new BasicDBObject();
basicDBObject.put("name", "guilherme");
basicDBObject.put("state", "happy");
dBCollection.insert(basicDBObject);
}
}
Error:(14, 21) java: no suitable method found for Insert(com.mongodb.Basicdbobject) method com.mongodb.Dbcollection.Insert(com.mongodb.Dbobject...) is not applicable (argument Mismatch; com.mongodb.Basicdbobject cannot be converted to com.mongodb.Dbobject[]) method com.mongodb.Dbcollection.Insert(java.util.List) is not applicable (argument Mismatch; com.mongodb.Basicdbobject cannot be converted to java.util.List)
even installing the two . jar has not yet worked
– Guilherme Lima
@Guilhermelima the code is tested in netbeans, what could be maybe there is the problem, You can edit your question and put the error log or what is not working please?
– novic
done, I’m using the intellij IDE
– Guilherme Lima
@Guilhermelima he is saying mixed type, you are sending a simple data and he is asking for a list of this given by error.! The funny thing about it is that it has both forms
– novic
@Guilhermelima which of the routines you are using I passed two?
– novic
I am using the first option that uses getDB, I tried the other also did not work
– Guilherme Lima
Let’s go continue this discussion in chat. @Guillhermelima
– novic
@Guilhermelima the solution is there for IDEA to remove those
.jar
and add these two in the links referencing the answer. Now it will work and give me a feedback! Edit the answer is at the end ...– novic