[CXX-80] Online Array example is not working Created: 19/Feb/13  Updated: 10/Apr/14  Resolved: 13/Mar/14

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: legacy-0.0-26compat-2.6.0-rc2

Type: Bug Priority: Minor - P4
Reporter: Adriaan Bredekamp Assignee: Tyler Brock
Resolution: Done Votes: 0
Labels: cxxmove, driver, legacy-cxx, windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

C++ with Visual Studio 2010 on Win XP



 Description   

Hallo,

I am using Mongo 2.08 with Visual C++ 2010 on Win Xp.

I need to add very large arrays, up to 6400 datapoints to my database. The data contained represent an FFT result which is then stored along with other data. My problem refers to adding such a large array. I worked through the array example but just adding each value with the "<<" operator of C++ is cumbersome and cout allows only 256 values if I remember correctly.

In the array example on mongodb.org the follow lines make an exception

vector<be> a = an_obj["x"].Array();
I am getting as output
"Mon Feb 18 10:03:52 dev: lastError==0 won't report:field not found, expected typ
e 4"

Obviously what is passed to it in the example is not seen as an array.

In the other direction the line (Obj to vector conversion)

bo myarray = an_obj["x"].Obj();

I am getting as output the exception again and error in the command window stating:
"Mon Feb 18 10:08:35 dev: lastError==0 won't report:invalid parameter: expected a
n object ()"

It compiles fine but does not run. I think if this could be made to work I should be able to make some progress again.

Can someone please check that the array example also actually works?



 Comments   
Comment by Githook User [ 12/Mar/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-80 add arrayExample to gitignore
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/ae9703d06fb7da5548ac088009a2b2a7485c69f8

Comment by Tyler Brock [ 12/Mar/14 ]

Hey Adriaan, I've added a better array example using some of the things I mentioned above to the source code of the repository and we are going to replace the old example that you found on the web with this one.

Please let me know if this has helped.

Comment by Githook User [ 12/Mar/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-80 make the example a bit more interesting
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/2a9474086b30a5a4140f5f094e77bc0dd9d87354

Comment by Githook User [ 12/Mar/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-80 minor changes
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/aa56996c278913ee6cf742a65e116fa9bc62c0f3

Comment by Githook User [ 12/Mar/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-80 adapt existing array example from psuedo code
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/703700c501fea7f7518cf415495ceada95fd770b

Comment by Tyler Brock [ 12/Mar/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/22

Comment by Tyler Brock [ 04/Mar/14 ]

If you'd like to avoid inserting it you can alternatively print it out by calling bob.obj().toString()

Comment by Tyler Brock [ 04/Mar/14 ]

Hi Adriaan,

If you want to avoid using the macros you can do something like this to build up the array:

// create a BSON object builder
BSONObjBuilder bob(64);
 
// create an array builder
BSONArrayBuilder bab;
 
// put some numbers into the array
bab.append(1);
bab.append(123);
 
// append the array to the BSON object using the key "array"
bob.appendArray("array", bab.arr());
 
// insert the BSON object
c.insert("test.collection", bob.obj());

Comment by Gary Murakami [ 05/Mar/13 ]

Note that this is a C++ driver issue, distinctly different from the C driver. The C++ driver is part of the Core Server, and this issue should probably be moved there.

Generated at Wed Feb 07 21:58:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.