GithubHelp home page GithubHelp logo

mongo's Issues

Error when using insert_one()

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.

Running the example

I am newbe to V, trying to run the exemple I get the following :
" error: cannot use &string as &char in argument 2 to C.bson_oid_to_string "

image

Can't run find

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]

can't run the example

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

Design and Planning

This issue is to discuss the planning of the mongo vlang driver.

  • Currently the implementation is a wrapper around the mongo-c-driver. Is it the long term solution?
  • Are we planning to develop a native vlang driver? Like mongo-go-driver?
  • Even if we keep the wrapping the mongo-c-driver, do we want a vlang native bson library? Similar to https://github.com/mongodb/mongo-go-driver/tree/master/bson
  • How to handler marshal and unmarshal between bson and vlang struct?

Errors in testing

v test src

Error 1

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

src/bson.c_structs.v

[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.
}

Error 2

warning: assignment from incompatible pointer type
tcc: error: undefined symbol 'mongoc_client_new_from_uri_with_error'

src/client.v

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)
}

Result

---- 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.