GithubHelp home page GithubHelp logo

isabella232 / mongo-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vlang/mongo

0.0 0.0 0.0 82 KB

Official MongoDB driver

License: MIT License

V 67.52% Verilog 0.05% Makefile 1.61% Coq 30.31% AMPL 0.52%

mongo-1's Introduction

Mongo MongoDB driver for vlang

Roadmap:

  • add basic fn to wrap mongo and bson
  • add sugar fn to get fields of bson
  • define required tasks to get a complete use of mongo with V
  • add more sugar fn (Ex: collection.insert(t T) inserts a V Struct in a collection)
  • add bulk query support (Ex: insert_many)
  • separate bson into a submodule of mongo Future:
  • Build a native bson vlang library
  • Build a native mongo vlang library

Dependencies

  • libmongoc
  • libbson

Examples

  • connect to mongo

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

    database := client.get_database('db_name')
  • select collection

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

    bson_document := mongo.new_from_json('{}')
  • append bool field to BSON document

    bson_document.append_bool('key' false)

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

  • insert one document

    mongo_uri := mongo.uri_new('mongodb://127.0.0.1:27017')
    client := mongo_uri.new_client()
    collection := client.get_collection('db_name', 'collection_name')
    bson_document := mongo.new_bson()
    bson_document.append_bool('key' false)
    collection.insert_one(bson_document)
  • find documents by query

      query := mongo.new_bson()
      query.append_bool('bool', true)
    
      bson_doc := mongo.new_bson()
      cursor := collection.find_with_opts(query)
    
      for cursor.next(&bson_doc) {
          str := mongo.as_canonical_extended_json(bson_doc)
          println(str)
      }
  • initialize BSON from JSON

    bson_doc := mongo.new_from_json('{"heeey": "howudoinggggg =)"}')
  • update value by selector and update

    selector := mongo.new_from_json('{"key":"value1"}')
    update := mongo.new_from_json('{"\$set":{"value":"key1"}}')
    
    collection.update_one(collection, selector, update)

mongo-1's People

Contributors

esquerbatua avatar medvednikov avatar

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.