Will insert(List) return null?
WriteResult result = collection.insert(List<DBObject>);
result.getError() -->Throws NullPointeException
In the above snippet, what may cause the return of null for WriteResult?
Will insert(List) return null?
WriteResult result = collection.insert(List<DBObject>);
result.getError() -->Throws NullPointeException
In the above snippet, what may cause the return of null for WriteResult?
Can you try providing a BasicDBList, which contains BasicDBObject instances.
For example:
BasicDBObject updateObject = new BasicDBObject();
BasicDBList dbList = createList(objects);
updateObject.append("$push", new BasicDBObject("collection", dbList));
WriteResult result = collection.insert(dbList);
...
private BasicDBList createList(List<SampleObject> list) {
BasicDBList result = new BasicDBList();
for (SampleObject obj: list) {
BasicDBObject dbObject = new BasicDBObject();
dbCar.append("name", obj.getName()); //for exmaple
result.add(dbObj);
}
return result;
}
It would probably return a NullPointerException because at the least the method is expecting a list that has at least one key to read in order to successfully insert something. Else it would be inserting, technically, a non-existent document.