MongoQuery

module
v0.0.0-...-e61580b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: GPL-3.0

README

Mongo Query

mongoquery is a Go package for parsing input strings into MongoDB queries with support for complex conditions.

screenshot

Installation

To use mongoquery, you can install it with go get:

go get github.com/Kryptonux/MongoQuery

Example

Here's an example of how to use mongoquery to construct and execute MongoDB queries:

package main

import (
	"fmt"

	"github.com/Kryptonux/MongoQuery/mongoquery"
)

func main() {
	// MongoDB connection details
	mongoURI := "mongodb://localhost:27017"
	databaseName := "your-database"
	collectionName := "your-collection"

	// Create a MongoDB client
	client, err := mongoquery.New(mongoURI, databaseName, collectionName)
	if err != nil {
		fmt.Printf("Error creating MongoDB client: %v\n", err)
		return
	}
	defer client.Close()

	// Input query string
	inputString := "_login.email_address: meow@protonmail.ch + _login.password_cracked: *"

	fmt.Println("Input Query: ", inputString)
	fmt.Println("MQuery Out.: ", mongoquery.ParseInputString(inputString))
	fmt.Println()

	// Execute the MongoDB query
	results, err := client.Query(inputString)
	if err != nil {
		fmt.Printf("Error executing MongoDB query: %v\n", err)
		return
	}
  
  // Process documents how ever you want but in this example we'll output how many results there is
	fmt.Printf("Matching documents: %v\n", len(results))
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL