www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - error connecting to mongodb atlas with vibe.d

reply notsteve <stevethe1st gmail.com> writes:
Hi,

I am trying to setup a simple webserver in D using vibe.d (0.9.4) 
and want to use mongoDB as a database. To achieve this, I've set 
up a mongoDB atlas instance with the following command inside the 
standard app.d file created by vibe.d

```
  string MongoURL = 
"mongodb://username:<password> cluster0-shard-00-01.gaetq.mongodb.net:27017";

     auto client = connectMongoDB(MongoURL);

```

but am getting error [1] below.

Alternatively if I use the following path to the instance

```
     string MongoURL =       
"mongodb://username:password cluster0-shard-00-01.gaetq.mongodb.net:27017/myFirstDatabase?ssl=true&sslverifycertificate=false";

```

I get error [2].

I have tried accessing this instance using other programming 
languages and am not having any issues so am sure it is not an 
issue with the database instance. Does anyone have experience 
with this?



Error 1:
```
object.Exception ../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/v
be/core/net.d(777): Reached end of stream while reading data.
----------------
source/app.d:29 pure  safe noreturn 
std.exception.bailOut!(Exception).bailOut(immutable(char)[], 
ulong, scope const(char)[]) [0x10af61e82]
/Library/D/dmd/src/phobos/std/exception.d:439 pure  safe bool 
std.exception.enforce!().enforce!(bool).enforce(bool, lazy 
const(char)[], immutable(char)[], ulong) [0x10af641ae]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core/net.d:777
 safe bool vibe.core.net.TCPConnection.read(scope ubyte[],
eventcore.driver.IOMode).__lambda4!(core.time.Duration).__lambda4
core.time.Duration) [0x10b1f7d4b]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core/net.d:897
 safe void vibe.core.net.loopWithTimeout!(vibe.core.net.TCPC
nnection.read(scope ubyte[], eventcore.driver.IOMode).__lambda4,
vibe.core.net.ReadTimeoutException).loopWithTimeout(core.time.Duration,
immutable(char[])) [0x10b1f7bea]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core/net.d:773
 safe ulong vibe.core.net.TCPConnection.read(scope ubyte[],
eventcore.driver.IOMode) [0x10b1f5b3e]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core/net.d:789
 safe void vibe.core.net.TCPConnection.read(scope ubyte[]) [0x10b1f5b80]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/internal/
nterfaceproxy.d:310  safe void
vibe.internal.interfaceproxy.InterfaceProxy!(vibe.core.stream.Stream).InterfaceProxy.ProxyImpl!(vibe.core.net.TCPConnection).ProxyImpl.__mixin8.__mixin3.__mixin3.__mixin3.__mixin3._
mixin2.read(void[], scope ubyte[]) [0x10af67273]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/internal/
nterfaceproxy.d:199  safe void
vibe.internal.interfaceproxy.InterfaceProxy!(vibe.core.stream.Stream).InterfaceProxy.__mixin22.__mixin3.__mixin3.__mixin3.__mixin3
__mixin2.read(scope ubyte[]) [0x10af661e9]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:538  safe void
vibe.db.mongo.connection.MongoConnection.recv(ubyte[]) [0x10afab0b2]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:523  safe int
vibe.db.mongo.connection.MongoConnection.recvInt() [0x10afaad11]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:437  safe int
vibe.db.mongo.connection.MongoConnection.recvReply!(vibe.data.bson.
son).recvReply(int, scope void delegate(long, vibe.db.mongo.flags.ReplyFlags,
int, int)  safe, scope void delegate(ulong, ref vibe.data.bson.Bson)  safe)
[0x10afaed2b]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:322  safe void
vibe.db.mongo.connection.MongoConnection.query!(vibe.data.bson.Bson).quer
(immutable(char)[], vibe.db.mongo.flags.QueryFlags, int, int,
vibe.data.bson.Bson, vibe.data.bson.Bson, scope void delegate(long,
vibe.db.mongo.flags.ReplyFlags, int, int)  safe, scope void delegate(ulong, ref
vibe.data.bson.Bson)  safe) [0x10afaf5d3]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:223  safe void
vibe.db.mongo.connection.MongoConnection.connect() [0x10afa941a]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:64
 safe vibe.db.mongo.connection.MongoConnection
vibe.db.mongo.client.MongoClient.__ctor(immutable(char)[]).__lambda4()
[0x10af802e7]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core
connectionpool.d:94  safe
vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnecti
n).LockedConnection vibe.core.connectionpool.ConnectionPool!(vibe.db.mongo.connection.MongoConnection).ConnectionP
ol.lockConnection() [0x10af80e17]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:170
 safe vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnecti
n).LockedConnection vibe.db.mongo.client.MongoClient.lockConnection()
[0x10af80670]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:71
 safe vibe.db.mongo.client.MongoClient
vibe.db.mongo.client.MongoClient.__ctor(immutable(char)[]) [0x10af80263]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/mongo.d:89
 safe vibe.db.mongo.client.MongoClient
vibe.db.mongo.mongo.connectMongoDB(immutable(char)[]) [0x10afc030e]
source/app.d:11 _Dmain [0x10af61ae9]
Program exited with code 1
```



Error 2:
```
object.Exception ../../../.dub/packages/vibe-d-0.9.4/vibe-d/data/vi
e/data/bson.d(813): BSON value is type 'int_', expected to be one of [double_]
----------------
../../../.dub/packages/vibe-d-0.9.4/vibe-d/data/vibe/data/bson.d:813 const
 safe void vibe.data.bson.Bson.checkType(in vibe.data.bson.Bson.Type[]...)
[0x1099bbff5]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/data/vibe/data/bson.d:396 const
 property  safe double vibe.data.bson.Bson.get!(double).get() [0x10980a7d6]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:640  safe void
vibe.db.mongo.connection.MongoConnection.scramAuthenticate().__lambda8!(ulong,
vibe.data.bson.Bson).__lambda8(ulong, ref vibe.data.bson.Bson) [0x109802a5c]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:477  safe int
vibe.db.mongo.connection.MongoConnection.recvReply!(vibe.data.bson.
son).recvReply(int, scope void delegate(long, vibe.db.mongo.flags.ReplyFlags,
int, int)  safe, scope void delegate(ulong, ref vibe.data.bson.Bson)  safe)
[0x109804f15]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:322  safe void
vibe.db.mongo.connection.MongoConnection.query!(vibe.data.bson.Bson).quer
(immutable(char)[], vibe.db.mongo.flags.QueryFlags, int, int,
vibe.data.bson.Bson, vibe.data.bson.Bson, scope void delegate(long,
vibe.db.mongo.flags.ReplyFlags, int, int)  safe, scope void delegate(ulong, ref
vibe.data.bson.Bson)  safe) [0x1098055a3]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:634  safe void
vibe.db.mongo.connection.MongoConnection.scramAuthenticate() [0x1098023e5]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mo
go/connection.d:269  safe void
vibe.db.mongo.connection.MongoConnection.connect() [0x1097ff75a]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:64
 safe vibe.db.mongo.connection.MongoConnection
vibe.db.mongo.client.MongoClient.__ctor(immutable(char)[]).__lambda4()
[0x1097d62b7]
../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/vibe/core
connectionpool.d:94  safe
vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnecti
n).LockedConnection vibe.core.connectionpool.ConnectionPool!(vibe.db.mongo.connection.MongoConnection).ConnectionP
ol.lockConnection() [0x1097d6de7]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:170
 safe vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnecti
n).LockedConnection vibe.db.mongo.client.MongoClient.lockConnection()
[0x1097d6640]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/client.d:71
 safe vibe.db.mongo.client.MongoClient
vibe.db.mongo.client.MongoClient.__ctor(immutable(char)[]) [0x1097d6233]
../../../.dub/packages/vibe-d-0.9.4/vibe-d/mongodb/vibe/db/mongo/mongo.d:89
 safe vibe.db.mongo.client.MongoClient
vibe.db.mongo.mongo.connectMongoDB(immutable(char)[]) [0x1098162de]
source/app.d:11 _Dmain [0x1097b7a9d]
Program exited with code 1
```
Apr 30 2022
next sibling parent Tejas <notrealemail gmail.com> writes:
On Saturday, 30 April 2022 at 14:29:56 UTC, notsteve wrote:
 Hi,

 I am trying to setup a simple webserver in D using vibe.d 
 (0.9.4) and want to use mongoDB as a database. To achieve this, 
 I've set up a mongoDB atlas instance with the following command 
 inside the standard app.d file created by vibe.d

 [...]
Don't know if this will help or not, but someone wrote a book explaining vibed (and it's pretty recent too), maybe it'll contain some info regarding your issue https://github.com/reyvaleza/vibed/blob/main/BuildWebAppsinVibe.pdf Hope it helps!
Apr 30 2022
prev sibling parent Arjan <arjan ask.me.to> writes:
On Saturday, 30 April 2022 at 14:29:56 UTC, notsteve wrote:
 Hi,

 I am trying to setup a simple webserver in D using vibe.d 
 (0.9.4) and want to use mongoDB as a database. To achieve this, 
 I've set up a mongoDB atlas instance with the following command 
 inside the standard app.d file created by vibe.d

 ```
  string MongoURL = 
 "mongodb://username:<password> cluster0-shard-00-01.gaetq.mongodb.net:27017";

     auto client = connectMongoDB(MongoURL);

 ```

 but am getting error [1] below.

 Alternatively if I use the following path to the instance

 ```
     string MongoURL =       
 "mongodb://username:password cluster0-shard-00-01.gaetq.mongodb.net:27017/myFirstDatabase?ssl=true&sslverifycertificate=false";

 ```

 I get error [2].

 I have tried accessing this instance using other programming 
 languages and am not having any issues so am sure it is not an 
 issue with the database instance. Does anyone have experience 
 with this?



 Error 1:
 ```
 object.Exception ../../../.dub/packages/vibe-core-1.22.3/vibe-core/source/v
be/core/net.d(777): Reached end of stream while reading data.
 ----------------
 ```
https://github.com/vibe-d/vibe-core/blob/v1.22.3/source/vibe/core/net.d#L777 Apparently, no data is received anymore within the remaining time duration.
 Error 2:
 ```
 object.Exception ../../../.dub/packages/vibe-d-0.9.4/vibe-d/data/vi
e/data/bson.d(813): BSON value is type 'int_', expected to be one of [double_]
 ```
https://github.com/vibe-d/vibe.d/blob/v0.9.4/data/vibe/data/bson.d#L813 There is clearly something wrong with the type expected and provided. Check the schemes/layouts.
May 01 2022