/// <summary> /// Array of strings /// { 'stuff': ['apple, 3, 2.14] } --> { 'stuff': { '0': 'apple', '1': 3, '2': 2.14 } } /// </summary> public void WriteStringInt32DoubleMixedArray(Stream stream) { var root = new BSONDocument(); var array = new BSONElement[] { new BSONStringElement("apple"), new BSONInt32Element(3), new BSONDoubleElement(2.14D) }; root.Set(new BSONArrayElement("stuff", array)); root.WriteAsBSON(stream); }
private byte[] elmBin(BSONElement elm) { if (elm == null || elm is BSONNullElement) { return(null); } return(((BSONBinaryElement)elm).Value.Data); }
private string elmStr(BSONElement elm) { if (elm == null || elm is BSONNullElement) { return(null); } return(((BSONStringElement)elm).Value); }
private void putCore(string table, byte[] key, BSONElement value, int slidingExpirationDays, DateTime?absoluteExpirationDateUtc) { var db = MongoClient.DatabaseFromConnectString(EffectiveConnectionString); var doc = new BSONDocument() .Set(RowConverter.ByteBufferID_CLRtoBSON(MongoQuery._ID, key)) .Set(value) .Set(new BSONDateTimeElement(FIELD_LAST_USE_DATE, App.TimeSource.UTCNow)) .Set(absoluteExpirationDateUtc.HasValue ? (BSONElement) new BSONDateTimeElement(FIELD_ABSOLUTE_EXPIRATION_DATEUTC, absoluteExpirationDateUtc.Value) : new BSONNullElement(FIELD_ABSOLUTE_EXPIRATION_DATEUTC)) .Set(slidingExpirationDays > -1 ? (BSONElement) new BSONInt32Element(FIELD_SLIDING_EXPIRATION_DAYS, slidingExpirationDays) : new BSONNullElement(FIELD_SLIDING_EXPIRATION_DAYS)); db[table].Save(doc); }
private void putCore(string table, byte[] key, BSONElement value, int slidingExpirationDays, DateTime?absoluteExpirationDateUtc) { //todo: Why do we obtain ref to db on very put, need to consider cache for speed var db = App.GetMongoDatabaseFromConnectString(EffectiveConnectionString); var doc = new BSONDocument() .Set(DataDocConverter.ByteBufferID_CLRtoBSON(MongoQuery._ID, key)) .Set(value) .Set(new BSONDateTimeElement(FIELD_LAST_USE_DATE, App.TimeSource.UTCNow)) .Set(absoluteExpirationDateUtc.HasValue ? (BSONElement) new BSONDateTimeElement(FIELD_ABSOLUTE_EXPIRATION_DATEUTC, absoluteExpirationDateUtc.Value) : new BSONNullElement(FIELD_ABSOLUTE_EXPIRATION_DATEUTC)) .Set(slidingExpirationDays > -1 ? (BSONElement) new BSONInt32Element(FIELD_SLIDING_EXPIRATION_DAYS, slidingExpirationDays) : new BSONNullElement(FIELD_SLIDING_EXPIRATION_DAYS)); db[table].Save(doc); }
public override object Visit(BinaryExpression binary) { binary.NonNull(nameof(binary)); if (!binary.Operator.NonBlank(nameof(binary.Operator)).IsOneOf(Translator.BinaryOperators)) { throw new ASTException(StringConsts.AST_UNSUPPORTED_BINARY_OPERATOR_ERROR.Args(binary.Operator)); } var op = MapBinaryOperator(binary.Operator); var left = binary.LeftOperand .NonNull(nameof(binary.LeftOperand)) .Accept(this); var isNull = (binary.RightOperand == null || binary.RightOperand is ValueExpression ve && ve.Value == null); if (left is string identifier) //{identifier: {$lt: value} } { if (isNull) { return(new BSONDocumentElement(identifier, new BSONDocument().Set(new BSONNullElement(op)))); } var value = binary.RightOperand.Accept(this); var right = new BSONDocument(); if (value is IEnumerable vie) { //todo: need to handle array // var arr = vie.Cast<object>().Select( e => new BSONElement(e)); // right.Set(new BSONArrayElement(op, arr)); } else { try { right.Add(op, value, false, true); } catch { throwSyntaxErrorNear(binary, "unsupported RightOperand value `{0}`".Args(value == null ? "<null>" : value.GetType().Name)); } } return(new BSONDocumentElement(identifier, right)); } if (left is BSONElement complex) { BSONElement right = null; if (isNull) { throwSyntaxErrorNear(binary, "unexpected null in compound statement"); } else { right = binary.RightOperand.Accept(this) as BSONElement; if (right == null) { throwSyntaxErrorNear(binary, "unsupported RightOperand value"); } } return(new BSONArrayElement(op, new[] { complex, right })); } return(throwSyntaxErrorNear(binary, "unsupported construct")); }