Skip to content
/ mongov Public

mongo driver for V lang based on libmongoc and libbson

Notifications You must be signed in to change notification settings

Chank1e/mongov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VMongo mongo drive for vlang

Dependencies

  • libmongoc
  • libbson

Modules

Examples

  • connect to mongo

    uri := 'mongodb://127.0.0.1:27017'
    mongo.initialize()
    
    mongo_uri := mongo.uri_new(uri)
    client := mongo.client_new_from_uri(mongo_uri)
  • select database

    database := mongo.client_get_database(client, 'db_name')
  • select collection

    collection := mongo.client_get_collection(client, 'db_name', 'collection_name')
  • create new BSON document

    bson_document := bson.new()
  • append bool field to BSON document

    bson.append_bool(bson_document, 'key' false)

    you can add field of any type you want, checkout here

  • insert one document

    uri := 'mongodb://127.0.0.1:27017'
    mongo.initialize()
    
    mongo_uri := mongo.uri_new(uri)
    client := mongo.client_new_from_uri(mongo_uri)
    collection := mongo.client_get_collection(client, 'db_name', 'collection_name')
    bson_document := bson.new()
    bson.append_bool(bson_document, 'key' false)
    mongo.collection_insert_one (collection, bson_document)
  • find documents by query

    query := bson.new()
    bson_doc := bson.new()
    bson.append_bool(query, 'bool', true)
    
    cursor := mongo.collection_find_with_opts(collection, query)
    
    for mongo.cursor_next(cursor, &bson_doc) {
        str := bson.as_canonical_extended_json(bson_doc)
        println(str)
    }
  • initialize BSON from JSON 😍

    bson_doc := bson.new()
    json_doc := '{"heeey": "howudoinggggg =)"}'
    bson.init_from_json(bson_doc, json_doc)
  • update value by selector and update 🐸

    selector := bson.new()
    update := bson.new()
    
    bson.init_from_json(selector, '{"key":"value1"}')
    bson.init_from_json(update, '{"\$set":{"value":"key1"}}')
    
    
    mongo.collection_update_one(collection, selector, update)

About

mongo driver for V lang based on libmongoc and libbson

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages