vlang / mongo Goto Github PK
View Code? Open in Web Editor NEWOfficial MongoDB driver
License: MIT License
Official MongoDB driver
License: MIT License
Error when using function collection.insert_one()
.
Code:
module sublib
import mongo
fn main() {
mongo_uri := mongo.uri_new('xxx')
client := mongo_uri.get_database('discord_bot')
col := client.get_collection('discord_bot', 'user_data')
col.insert_one({
'str': 'string'
'number': 2
'float': 2.1
'boolean': true
})
response := col.find({
'str': 'string'
}).lean()
assert response[0].as_map()['str'] or { 0 }.str() == 'string'
}
Error:
C:/Users/xxx/.vmodules/mongo/src/collection.v:36:75: error: cannot use `&&C.bson_t` as `&C.bson_t` in argument 4 to `C.mongoc_collection_insert_one`
34 | reply := new_bson()
35 |
36 | result := C.mongoc_collection_insert_one(collection, document_bson_t, 0, &reply, &error)
| ~~~~~~
37 | unsafe { println(C.bson_as_json(&reply, 0).vstring()) }
38 | if unsafe { error.message.vstring() != '' } {
I've already updated V and Mongo-V. Hopefully this question is adequately formatted.
I'm having trouble doing a basic find.
query := mongo.new_from_json('{}')
count := collection.count_documents(query)
println(count) // 69 return ok
bson_doc := mongo.new_bson()
cursor := collection.find(query)
for cursor.next(&bson_doc) {
str := mongo.as_canonical_extended_json(bson_doc)
println(str)
}
it returns me the following error:
mongo.v:19:20: error: unknown function: mongo.as_canonical_extended_json
17 |
18 | for cursor.next(&bson_doc) {
19 | str := mongo.as_canonical_extended_json(bson_doc)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 | println(str)
21 | }
# Ubuntu 20.04
# apt list --installed
libmongoc-1.0-0/focal,now 1.16.1-1build2 amd64 [installed]
libmongoc-dev/focal,now 1.16.1-1build2 amd64 [installed]
libbson-1.0-0/focal,now 1.16.1-1build2 amd64 [installed]
libbson-dev/focal,now 1.16.1-1build2 amd64 [installed]
I am having an issue running the example
mongo.v:20:15: error: undefined ident: `bson`
18 | }
19 |
20 | user_bson := bson.new_from_json(json.encode(app))
| ~~~~
21 |
22 | mongo.collection_insert_one(collection, user_bson)
mongo.v:22:8: error: unknown function: mongo.collection_insert_one
20 | user_bson := bson.new_from_json(json.encode(app))
21 |
22 | mongo.collection_insert_one(collection, user_bson)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 | }
I am using ubuntu 20.04 and installed the dependencies as following:
sudo apt-get install libmongoc-1.0-0
sudo apt-get install libbson-1.0
v install --git https://github.com/vlang/mongo
Hey,
I've already wrote some code for mongo on VLang
You can check it out here https://github.com/Chank1e/mongov
Would be great if I can help you with this piece of code)
This issue is to discuss the planning of the mongo vlang driver.
v test src
src/cursor.v:62:17: error: reference field `C.bson_t.padding` must be initialized
60 | }
61 |
62 | document := &C.bson_t{}
| ~~~~~~~~
63 |
64 | mut count := skip
[typedef]
pub struct C.bson_t {
flags u32 // Internal flags for the bson_t.
len u32 // Length of BSON data.
padding &u8 = unsafe { nil } // Padding for stack allocation.
}
warning: assignment from incompatible pointer type
tcc: error: undefined symbol 'mongoc_client_new_from_uri_with_error'
pub fn new_client(uri string) &C.mongoc_client_t {
mongoc_uri := C.mongoc_uri_new(uri.str)
// mut error := C.bson_error_t{}
// return C.mongoc_client_new_from_uri_with_error(mongoc_uri, &error)
return C.mongoc_client_new_from_uri(mongoc_uri)
}
---- Testing... -----------------------------------------------------------------------------------------------------------------------------
OK [1/2] 170.052 ms /mongo/src/bson_test.v
OK [2/2] 265.810 ms /mongo/src/collection_test.v
---------------------------------------------------------------------------------------------------------------------------------------------
Summary for all V _test.v files: 2 passed, 2 total. Runtime: 436 ms, on 1 job.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.