[SERVER-20309] Mongo data structure similar to Java's Map Created: 07/Sep/15  Updated: 09/Oct/15  Resolved: 09/Oct/15

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: 3.0.0
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Hendra Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
Participants:

 Description   

I wish to know if it's possible to request for a feature in mongoDB for a data structure that behaves like Java Map. So, currently, when I save HashMap, mongo will convert this to objects, not arrays. This makes "merge" operation like Java Hashmap's putAll() method really hard.
Thanks



 Comments   
Comment by Stennie Steneker (Inactive) [ 15/Sep/15 ]

Hi Hendra,

The SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag where your questions will reach a larger audience.

I noticed this question has already been posted on the mongodb-user group , so someone will follow up there.

Thanks,
Stephen

Comment by Hendra [ 07/Sep/15 ]

Hi all,

I'm storing exchange rate where the POJO looks like

public class Rates{
	private String currency;
	private Map<String, Long> rate;
}

the problem here is the "rate" field. I prefer if there's a function in mongo that would do like:

db.rates.update({"currency":"SGD"},{$merge:{"rate":$each:[{"2015-01-01":125},{"2015-02-02":133}]}},{upsert:true})

which would have upsert behavior.

Is this doable with the latest mongoDB version? What are my options?

Thanks

Generated at Thu Feb 08 03:53:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.