Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
dj-nitehawk / Program.cs
Last active May 25, 2021
override DBContext methods to add global filters
View Program.cs
using MongoDB.Entities;
using System.Threading.Tasks;
namespace TestApplication
{
public class Employee : Entity
{
public string Name { get; set; }
public bool IsInactive { get; set; }
}
@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 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 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
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
View Program.cs
using MongoDB.Entities;
using MongoDB.Entities.Core;
using System.Collections.Generic;
using System.Linq;
namespace TestApp
{
public class Zone : Entity
{
public int SqlId { get; set; }
@dj-nitehawk
dj-nitehawk / Program.cs
Created Jul 3, 2020
deeply nested shitstorm ;-)
View Program.cs
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using MongoDB.Entities;
using MongoDB.Entities.Core;
using System.Linq;
namespace TestApp
{
public class Team : Entity
View Program.cs
using MongoDB.Entities;
using System;
using System.Threading.Tasks;
namespace TestProg
{
internal static class Program
{
public class ArtGallery : 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
{