Giter VIP home page Giter VIP logo

mongov's Introduction

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)

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.