0

I have some fields in mongodb such as name as string, id as integer, address as arraylist and so on. I need name as "what data type". I need to get the name datatype.

This is my coding config the netbeans and MongoDB

MongoClient mongoClient = new MongoClient(mongopath);
DB db = mongoClient.getDB(dbname);
DBCollection coll = db.getCollection(dbname);
DBCursor cursor = coll.find();

Can someone explain this?

1 Answer 1

1

You can try below:

BasicDBObject doc = cursor.hasNext() ? cursor.next() : new BasicDBObject();
Object name = doc.get("name");
String typeString = name == null ? "null" : name.getClass().toString();
Sign up to request clarification or add additional context in comments.

4 Comments

Thank u Wizard.. It working fine.. i got below output class java.lang.String.. I need String data type only. Can u explain this?
@Bass: String typeString = name == null ? "null" : name.getClass().getSimpleName();
Thank u Wizard and i have Other one doubt please check this url stackoverflow.com/questions/25665118/…
@Bass, I'm not familiar with that. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.