MongoDB: Minimum working example #4810
Replies: 12 comments 23 replies
-
Does installing and using CMake module from installation work? |
Beta Was this translation helpful? Give feedback.
-
what do you mean by "CMake module from installation " ?
I used cmake v3.30.3 |
Beta Was this translation helpful? Give feedback.
-
You wrote above that you did not install. Install Poco to some directory:
Then use CMake That is the supported way and should work. |
Beta Was this translation helpful? Give feedback.
-
Another option for simple examples like yours is to define |
Beta Was this translation helpful? Give feedback.
-
Now that I managed to build Poco, and link it to my example code, the DB is not added after running the executable, no error reported, the server is running in localhost:default port, and I launched a nodejs app that writes into the db, and It worked, so the problem is not in the server side. I am not sure what went wrong, I can't find any doc about this.
TCP traffic capture shows TCP handshakes and insertion request submitted. |
Beta Was this translation helpful? Give feedback.
-
Use the function that captures the response and then print it. See unit tests. |
Beta Was this translation helpful? Give feedback.
-
this is what I get :
|
Beta Was this translation helpful? Give feedback.
-
Ok, so my previous code was using the deprecated wire protocol OP_INSERT.
With the example code from unit test testOpCmdInsert() in "MongoDBTestOpMsg.cpp" :
|
Beta Was this translation helpful? Give feedback.
-
Response is of type OpMsgMessage, OpMsgMessage has no member function toString |
Beta Was this translation helpful? Give feedback.
-
@ssooffiiaannee, it seems that there is something causing the problem on your end: either build environment, compiler, ... I just tested the attached project on MacOS 15 and MongoDB 8.0.3 and it works fine.
Output:
|
Beta Was this translation helpful? Give feedback.
-
I may have found the root cause, it's a malformation of the OpMsg frame, coming from OpMsgMessage.cpp line 234 :
And as a consequence, PAYLOAD_TYPE_0 is written as a 4 byte binary instead of 1 in the OpMsg Frame, the other 3 bytes of 0x00s push the document length's least significant bits into higher addresses, leading to a Big Endian representation of the Document length field (654311424 instead of 39) because server sees 0x00 0x00 0x00 0x27 as next field due to MSBs of payload type. Seems to affect GCC versions < 10.1, and MSVC 15, and maybe other versions. Next steps : either upgrade GCC version to versions >= 10.1 (Readme shows 8.0) I'll push the change after your confirmation. |
Beta Was this translation helpful? Give feedback.
-
PR #4822. |
Beta Was this translation helpful? Give feedback.
-
Os : Windows 11
MSVC 2017
Goal:
Make a minimum working example of a MongoDB client writing to a DB (make it compile at least, then make it work)
Code example :
Command line used :
I have cloned the project to : D:\poco
I have built the project in D:\poco\cmake-build folder
I did not install, I'd rather link to the build folder
"C:\path\to\mvs\2017\Community\Common7\Tools\VsDevCmd.bat"
"C:\path\to\mvs\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe" /std:c++17 /EHsc \mongodb_testing.cpp /I"D:\poco\MongoDB\include" /I"D:\poco\Net\include" /I"D:\poco\Foundation\include" /link "D:\poco\cmake-build\lib\PocoFoundation.lib"
Error:
I can't find the PocoFoundationmt lib after the build, I don't know why it is trying to link to a non-existant library
Beta Was this translation helpful? Give feedback.
All reactions