小编atb*_*btg的帖子

如何使用官方c#驱动程序在MongoDB中使用Update.Set更新多个字段?

以下代码将允许我更新FirstName ="john"和LastName ="Doe"的电子邮件.如何在不使用Save()方法的情况下更新电子邮件和电话?

MongoDB.Driver.MongoServer _server = MongoDB.Driver.MongoServer.Create("mongodb://localhost");
MongoDB.Driver.MongoDatabase _dataBase = _server.GetDatabase("test");
MongoDB.Driver.MongoCollection<Person> _person = _dataBase.GetCollection<Person>("person");

//Creat new person and insert it into collection
ObjectId newId  = ObjectId.GenerateNewId();
Person newPerson = new Person();
newPerson.Id = newId.ToString();
newPerson.FirstName = "John";
newPerson.LastName = "Doe";
newPerson.Email = "john.doe@gmail.com";
newPerson.Phone = "8005551222";
_person.Insert(newPerson);

//Update phone and email for all record with firstname john and lastname doe
MongoDB.Driver.Builders.QueryComplete myQuery = MongoDB.Driver.Builders.Query.And(MongoDB.Driver.Builders.Query.EQ("FirstName", "John"),    MongoDB.Driver.Builders.Query.EQ("LastName", "Doe"));
MongoDB.Driver.Builders.UpdateBuilder update = MongoDB.Driver.Builders.Update.Set("Email", "jdoe@gmail.com");

_person.Update(myQuery, update);
Run Code Online (Sandbox Code Playgroud)

.net c# mongodb mongodb-.net-driver

42
推荐指数
4
解决办法
4万
查看次数

如何在mongodb中找到最小值

你怎么做相当于

SELECT 
  MIN(Id) AS MinId
FROM
  Table
Run Code Online (Sandbox Code Playgroud)

在MongoDB中.看起来我将不得不使用MapReduce,但我找不到任何显示如何执行此操作的示例.

谢谢.

mongodb mongodb-.net-driver

37
推荐指数
3
解决办法
5万
查看次数

你如何使用剃刀包含.html或.asp文件?

是否可以在Razor视图引擎中使用服务器端包含.html或.asp文件?我们有一个.html文件和.asp文件,其中包含用于我们所有网站的网站菜单.目前我们使用服务器端包括我们所有的网站,所以我们只需要在一个地方更改mensu.

我在_Layout.cshtml的正文中有以下代码

<body>
<!--#include virtual="/serverside/menus/MainMenu.asp" -->   
<!--#include virtual="/serverside/menus/library_menu.asp" -->
<!--#include virtual="/portfolios/serverside/menus/portfolio_buttons_head.html" -->
@RenderBody()
</body>
Run Code Online (Sandbox Code Playgroud)

如果我执行视图源,而不是包含文件的内容,我会看到文字文本.

" <!--#include virtual="/serverside/menus/MainMenu.asp" --> 
    <!--#include virtual="/serverside/menus/library_menu.asp" -->
    <!--#include virtual="/portfolios/serverside/menus/portfolio_buttons_head.html" -->"
Run Code Online (Sandbox Code Playgroud)

razor asp.net-mvc-3

34
推荐指数
5
解决办法
7万
查看次数

你可以为不同的按钮使用相同的OnClickListener吗?

在android中,我可以为不同的按钮使用相同的OnClickListener吗?如果是,我如何从哪个按钮生成点击?我目前有4个按钮,每个按钮都有自己的OnClickListener.除了单击按钮的文本之外,每个OnClickListener都执行相同的操作.我想创建一个OnClickListener,但我无法弄清楚如何确定单击哪个按钮.谢谢

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        mTts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {

            @Override
            public void onInit(int arg0) {
                // TODO Auto-generated method stub

            }
        });
        setContentView(R.layout.home);
        Button button1 = (Button)findViewById(R.id.button1);
        Button button2 = (Button)findViewById(R.id.button2);
        Button button3 = (Button)findViewById(R.id.button3);
        Button button4 = (Button)findViewById(R.id.button4);

        //Load First Word
        button1.setOnClickListener(button1ClickListener);
        button2.setOnClickListener(button2ClickListener);
        button3.setOnClickListener(button3ClickListener);
        button4.setOnClickListener(button4ClickListener);

    }
Run Code Online (Sandbox Code Playgroud)

侦听器的代码,其中不同部分以粗体显示

private OnClickListener button1ClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        **Button button = (Button)findViewById(R.id.button1);**
        handleButtonClick(button);
    }
};

private OnClickListener …
Run Code Online (Sandbox Code Playgroud)

android button

11
推荐指数
1
解决办法
1万
查看次数

如何在iOS中处理1到3个手指轻扫手势

我使用以下代码处理我的代码中的1个手指滑动:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)];
    [swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
    [swipe setDelaysTouchesBegan:YES];
    [[self view] addGestureRecognizer:swipe];
Run Code Online (Sandbox Code Playgroud)

我知道我可以添加以下行以使其处理2个手指滑动:

 [swipe setNumberOfTouchesRequired:2];
Run Code Online (Sandbox Code Playgroud)

但是,当我添加上面的代码时,由于现在所需的触摸次数为2,因此不再检测到手指滑动.我可以做些什么来使我的代码适用于1,2或3个手指滑动?

我尝试使用以下代码,但这不符合我的要求.

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:3];
    [panRecognizer setDelaysTouchesBegan:YES];
    [[self view] addGestureRecognizer:panRecognizer];
    [panRecognizer release];
Run Code Online (Sandbox Code Playgroud)

谢谢.

iphone objective-c ios swipe-gesture

8
推荐指数
2
解决办法
1万
查看次数

路径中的非法字符.使用Skip并使用IEnumerable时出错

嗨,我的控制器中有以下操作

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index()
{
    IEnumerable<SurveyResult> myresult = filterData();
    totalCount = myresult.Count<SurveyResult>();
    ViewBag.totalCount = totalCount;
    //myresult = myresult.Skip<SurveyResult>(100 * pageIndex).Take<SurveyResult>(100);
    return View(myresult);
}
Run Code Online (Sandbox Code Playgroud)

这是我的看法

@model IEnumerable<SurveyResult>
@{
    ViewBag.Title = "Survey Results";
}
@using (Html.BeginForm())
{

    <table class="std-tbl">
        <thead>
            <tr>
                <th>
                    DEL
                </th>
                ...

                <th>
                </th>
            </tr>
        </thead>
        @Html.DisplayFor(x => x, new { pageIndex = ViewBag.index })
    </table>
}
Run Code Online (Sandbox Code Playgroud)

我有一个SurveyResult的部分视图,但我不包括它,因为我认为它不相关.这是我的问题.上面的代码工作正常,但只要我取消注释以下行

myresult = myresult.Skip<SurveyResult>(100 * pageIndex).Take<SurveyResult>(100);
Run Code Online (Sandbox Code Playgroud)

我得到"路径中的非法字符."我认为它可以找到SurveyResult的partialView.我不明白为什么它可以在评论上面的行时找到它但是当它没有注释时却不能找到它?谢谢.

这是我的堆栈跟踪

[ArgumentException: Illegal characters in path.]
   System.IO.Path.CheckInvalidPathChars(String path) +126
   System.IO.Path.Combine(String path1, String path2) +38 …
Run Code Online (Sandbox Code Playgroud)

c# ienumerable asp.net-mvc-3

7
推荐指数
1
解决办法
2524
查看次数

如何检查Android中是否启用了按钮?

在Android中,我可以通过执行以下操作设置要启用或禁用的按钮:

button.setEnabled(true); 要么 button.setEnabled(false);

如何检查按钮启用状态是真还是假?

android button isenabled

6
推荐指数
2
解决办法
2万
查看次数

popviewcontroller没有调用viewWillappear

当用户点击按钮时,我使用以下代码显示上一个视图

[self.navigationController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

在上一个视图中,我覆盖了viewWillAppear来初始化一些东西.但是,似乎没有调用viewWillAppear.我把NSLog放在viewDidload,viewWillAppear,viewDidAppear中,只调用viewDidAppear.这是正常的行为吗?如果是,我应该覆盖什么事件,以便我可以进行初始化?谢谢.

按要求-viewWillAppear查看上一个视图

- (void)viewWillAppear:(BOOL)animated{

    NSLog(@"ViewWillAppear");
        //[[GameStore defaultStore] resetGame];
        [self setHangmanImage];

    NSLog([[[GameStore defaultStore] selectedList] label]);
        [labelListName setText:[NSString stringWithFormat:@"List Name: %@", [[[GameStore defaultStore] selectedList] label]]];
        [labelCurrentIndex setHidden:YES];
        [labelCurrentWord setHidden:YES];
        [[self navigationController] setNavigationBarHidden:NO];

        [FlurryAnalytics logEvent:@"GameViewController - viewWillAppear"];

        [self getNewQuestion];

    NSLog(@"ViewWillAppear finish");
    [super viewWillAppear:YES];

}
Run Code Online (Sandbox Code Playgroud)

我使用以下代码在app委托中设置UINavigationalController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    HomeViewController *hv = [[HomeViewController alloc] init];

    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:hv];

    // You can now release the itemsViewController here,
    // UINavigationController will retain it
    [hv release];

    // Place …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uinavigationcontroller

6
推荐指数
2
解决办法
9008
查看次数

如何在使用mongo csharp插入后获取rcently插入文档的_id?

我能够使用以下代码成功插入新文档,但我无法获取新插入文档的_id.

插入后,user为null.谢谢!

MongoServer server = MongoServer.Create();
MongoDatabase test = server.GetDatabase("Test");

MongoCollection<BsonDocument> users = test.GetCollection("Users");
BsonDocument user = new BsonDocument();
user.Add("FirstName", "John");
user.Add("LastName", "Michael");
user.Add("Address", "123 Main Street");
user.Add("City", "Newport Beach");
user.Add("State", "CA");
user.Add("ZipCode", "92660");
user.Add("Email", "John.Michael@myemail.com");
user.Add("CreatedDate", DateTime.Now);
user.Add("IPAddress", "10.1.1.1");

user = users.Save(user);

string idSTring = user["_id"].ToString().Replace("\"", "");
Run Code Online (Sandbox Code Playgroud)

c# mongodb mongodb-.net-driver

4
推荐指数
1
解决办法
6351
查看次数

如何添加bsondocuments列表作为bsondocument的元素

如何使用官方c#驱动程序创建以下文档?

{
    "name": "John Doe",
    "classess": [
        {
            "classname": "Class1"
        }
        {
            "classname": "Class2"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

以下代码不起作用

string cs = "mongodb://localhost";
MongoServer server = MongoServer.Create(cs);
MongoDatabase test = server.GetDatabase("test");

MongoCollection<BsonDocument> students = test.GetCollection("students");

BsonDocument doc = new BsonDocument();
doc.Add(new BsonElement("name", "John doe"));

//Create the list
List<BsonDocument> classes = new List<BsonDocument>();
classes.Add(new BsonDocument(new BsonElement("classname","Test1")));
classes.Add(new BsonDocument(new BsonElement("classname","Test2")));
Run Code Online (Sandbox Code Playgroud)

出于明显的原因,以下行将抛出错误.这样做的正确方法是什么?

doc.Add(new BsonElement("classess",classes));
students.Insert(doc);
Run Code Online (Sandbox Code Playgroud)

谢谢.

c# mongodb mongodb-.net-driver

1
推荐指数
1
解决办法
1万
查看次数

是否有比.aiff更小的文件大小更好的选项与AVAudioPlayer一起使用?

我正在使用AVAudioPlayer在我的应用程序中播放一个简短的一个或两个音节字.目前有250个.aiff文件,每个文件大约88KB到125KB.目前我的ipa文件是29Megs,我正在努力寻找减小尺寸的最佳方法,这样用户就不必有wifi来下载它.

每个声音片段长1至2.5秒.我不需要暂停,倒带,快进等.

根据我到目前为止所读到的内容,AVAudioPlayer只播放aiff,wav或caf,而且没有一个被压缩.关于我能做什么的任何建议?谢谢.

compression iphone objective-c avaudioplayer aiff

1
推荐指数
1
解决办法
998
查看次数

如何使用官方C#驱动程序在mongoDB中执行SQL Like运算符

如何使用官方c#驱动程序在mongodb中执行以下SQL查询?

Select * from tblUser where FirstName Like '%as%'
Run Code Online (Sandbox Code Playgroud)

mongodb sql-like mongodb-.net-driver

0
推荐指数
1
解决办法
3437
查看次数