2

Suppose we have the following documents:

  {{i:1},{i:9},{i:10}}
  {i:3}
  {{i:4},{i:0}}
  {{i:5},{i:-3},{i:30}}

each line represents a document

is it possible to save the values of i in an ArrayList or some kind of List in general?

I'm trying to achieve this in java

thanks in advance

1 Answer 1

1

If you alter your documents slightly as follows:

{ivalues:[{i:1},{i:9},{i:10}]}

Then you should be able to create the document in Java as follows:

ArrayList<DBObject> x = new ArrayList<DBObject>();
x.add(new BasicDBObject("i", 1));
x.add(new BasicDBObject("i", 9));
x.add(new BasicDBObject("i", 10));
BasicDBObject doc = new BasicDBObject("ivalues", x);

And save/retrieve it as normal.

Sign up to request clarification or add additional context in comments.

Comments

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.