Repository

Mongo

MongoDB driver for vlang

Getting start:

Installing dependeces

libmongoc (MongoDB C Driver) libbson (BSON library)

# Debian and Ubuntu
sudo apt-get install libmongoc-dev
sudo apt-get install libbson-1.0-0
# Fedora
dnf install mongo-c-driver
dnf install libbson
# CentOS and RHEL 7
yum install mongo-c-driver
yum install libbson
# macOS
brew install mongo-c-driver

Starting MongoDB

mongo --host localhost --port 27017

Installing mongo package from vpm

v install mongo

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

// insert collection
collection.insert_one({
  'str':     'string'
  'number':  2
  'float':   2.1
  'boolean': true
})

// find collection
response := collection.find({
  'str': 'string'
}).lean()

assert response[0].as_map()['str'] or { 0 }.str() == 'string'

About

0
246
1 year ago

Author

medvednikov