I am new to mongoDB and using java with mongoDB. I have a json where I want to retrieve the column names and not the value.I also need to store it in two different array.
Desired output is:
column [ ] = views, AddToCart, AddToWishList, ZoomedProductImage
list [ ] = fSymbol, num, operator
and the JSON:
{
"views": {
"fSymbol": "",
"num": 0.1,
"operator": "*"
},
"AddToCart": {
"fSymbol": "+",
"num": 0.15,
"operator": "*"
},
"AddToWishList": {
"fSymbol": "+",
"num": 0.1,
"operator": "*"
},
"ZoomedProductImage": {
"fSymbol": "+",
"num": 0.07,
"operator": "*"
}
}
Try keySet()
method.
BasicDBObject searchQuery = new BasicDBObject();
DBCursor cursor = table.find(searchQuery);
while (cursor.hasNext()) {
System.out.println(cursor.next().keySet());
}
check the docs
由于BasicDBObject扩展了HashMap,因此您只需从中获取键集。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.