Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
dj-nitehawk / Program.cs
Last active Jul 9, 2021
full watcher example
View Program.cs
using MongoDB.Bson;
using MongoDB.Entities;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace TestApplication
{
public static class Program
@dj-nitehawk
dj-nitehawk / Program.cs
Created Jul 7, 2021
nested lookup example
View Program.cs
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Entities;
using System.Threading.Tasks;
namespace ReferencedRelationshipExample
{
public class Author : Entity
{
public string Name { get; set; }
@dj-nitehawk
dj-nitehawk / Run.cs
Created Jul 7, 2021
async over sync wrapper
View Run.cs
public static class Run
{
private static bool IsDotNetFx =>
RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase);
private static readonly TaskFactory factory =
new TaskFactory(
CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
@dj-nitehawk
dj-nitehawk / Program.cs
Last active Apr 21, 2021
fuzzy text search with sorted results
View Program.cs
using MongoDB.Entities;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
{
public static class Program
{
public class Item : Entity
{
@dj-nitehawk
dj-nitehawk / Program.cs
Last active Jul 27, 2021
update by incrementing field
View Program.cs
using MongoDB.Entities; //https://mongodb-entities.com
using System;
using System.Threading.Tasks;
namespace TestApplication
{
public class Message : Entity
{
public string Content { get; set; }
public int Upvotes { get; set; }
@dj-nitehawk
dj-nitehawk / Program.cs
Created Mar 30, 2021
SCRAM-SHA-1 auth method
View Program.cs
var username = "user";
var password = "password";
MongoInternalIdentity internalIdentity = new("auth_db_name", username);
PasswordEvidence passwordEvidence = new(password);
MongoCredential mongoCredential = new("SCRAM-SHA-1", internalIdentity, passwordEvidence);
await DB.InitAsync("DatabaseName", new MongoClientSettings
{
Server = new MongoServerAddress("localhost", 27017),
@dj-nitehawk
dj-nitehawk / Program.cs
Last active Mar 31, 2021
advanced query injection
View Program.cs
using MongoDB.Entities;
using System;
using System.Text;
using System.Threading.Tasks;
namespace TestApplication
{
public class UserActivity : Entity
{
public string RawUrl { get; set; }
@dj-nitehawk
dj-nitehawk / Program.cs
Created Feb 5, 2021
resume token demo for watcher/change-stream
View Program.cs
using MongoDB.Bson;
using MongoDB.Entities;
using System;
using System.IO;
using System.Threading.Tasks;
namespace TestApplication
{
public class Book : Entity
{
@dj-nitehawk
dj-nitehawk / Program.cs
Created Dec 12, 2020
lookup one to many relationship
View Program.cs
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDB.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
{
public class Course : Entity
@dj-nitehawk
dj-nitehawk / Program.cs
Created Nov 26, 2020
reverse relationship access with many-to-many relationship
View Program.cs
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDB.Entities;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
{
public class User : Entity
{